<!--我的文章列表-->
<template>
  <div>
    <content-list v-bind:list="contentList" :pages="pages" :current-page="currentPage" :pageSize="pageSize"
                  v-bind:my-content="true" v-on:deleteSuccess="reload"
                  v-on:search="search($event)"
                  @changePage="changePage($event)"></content-list>
  </div>
</template>

<script>
import ContentList from "../components/ContentList";

const axios = require('axios');
export default {
  components: {
    ContentList
  },
  mounted: function () {
    this.reload();
  },
  methods: {
    search(content) {
      this.searchContent = content;
      this.currentPage = 1;
      this.reload();
    },
    changePage(page) {
      this.currentPage = page;
      this.reload();
    },
    reload() {
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
      axios.get("/api/content/list_my_contents?pageNum=" + this.currentPage + "&pageSize=20&content=" + this.searchContent)
        .then((res) => {
          console.log(res)
          if (res.data.code === 200) {
            this.contentList = res.data.data.list;
            this.currentPage = res.data.data.currentPage;
            this.pages = res.data.data.pages;
            this.pageSize = res.data.data.pageSize;
          } else {
            this.$message(res.data.msg);
          }
          loading.close();
        })
        .catch((err) => {
          loading.close();
        });
    }
  },
  data() {
    return {
      contentList: [],
      pages: 0,
      currentPage: 0,
      pageSize: 0,
      searchContent: ''
    };
  }
}
</script>

<style>

</style>
